package com.mipo.client.javase.j2se.mis;

import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.util.EntityUtils;

public class Main {
	public static void main(String[] args)  throws Exception {
		String url = "http://open.jztest.changyan.cn/sso/login?service=http://10.4.0.72/App.ResourceCloud/addons/library/sso/ssoservice.php";
		excuteGetRequest(url);
	}
	
	public static void excuteGetRequest(String url) throws Exception {
		
		CookieStore cookieStore = new BasicCookieStore();
		BasicClientCookie cookie = new BasicClientCookie("name", "zhaoke"); 
        cookie.setVersion(0);  
        cookie.setDomain("/pms/");   //设置范围
        cookie.setPath("/"); 
        cookieStore.addCookie(cookie);
		
		
		
		CloseableHttpClient httpClient = HttpClients.createDefault();
		HttpGet httpGet = new HttpGet(url);
		
		CloseableHttpResponse response = httpClient.execute(httpGet); // 4.3版本不设置超时的话，一旦服务器没有响应，等待时间N久(>24小时)。
		HttpEntity entity = response.getEntity(); // 返回报文实体
		StatusLine status = response.getStatusLine();
		System.out.println("返回的状态码为：" + status); // 具体返回码(200)为status.getStatusCode(); 
		String ret = EntityUtils.toString(entity); // 将返回报文实体转换为字符串
		System.out.println("返回的报文为：" + ret);
		EntityUtils.consume(entity);  // 释放是否可以去掉？
		response.close(); // 关闭资源,可以写在finally里
		httpGet.releaseConnection(); // 释放资源
		httpClient.close(); // 关闭资源
	}
	
	
	
	
}
